package Package5;

public class twoArr {
    public static void main(String[] args) {
        //创建二维数组
        int[][] arr = new int[][]{
                {1, 2, 3, 4},
                {5, 6, 7, 8, 9, 10}
        };

        //遍历二维数组
        for (int i = 0; i < arr.length; i++) {
            //arr[i] 是二维数组的 元素， 也是每个一位数组的首地址及数组名
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }

        //二维数组的动态初始化
        int[][] arr2 = new int[3][5];
        arr2[2][3] = 17;
        for (int i = 0; i < arr2.length; i++) {
            for (int j = 0; j < arr2[i].length; j++) {
                System.out.print(arr2[i][j] + " ");
            }
            System.out.println();
        }

        int[][] arr3 = new int[2][];
        int[] a = {9, 82, 8, 4};
        int[] b = {1, 8, 9};
        arr3[0] = a;
        arr3[1] = b;

        for (int i = 0; i < arr3.length; i++) {
            for (int j = 0; j < arr3[i].length; j++) {
                System.out.print(arr3[i][j] + " ");
            }
            System.out.println();
        }

        //求季/年度总营业额
        int[][] arr4 = new int[][]{
                {1, 2, 3},
                {4, 5, 6},
                {7, 8, 9},
                {10, 11, 12}
        };
        int sum = 0;
        int[] sumArr = new int[arr4.length];
        for (int i = 0; i < arr4.length; i++) {
            sumArr[i] = getSum(arr4[i]);
            sum += sumArr[i];
            System.out.println("第" + (i + 1) + "个季度的营业额是：" + sumArr[i]);
        }
        System.out.println("年度营业额是：" + sum);
    }

    public static int getSum(int[] arr) {
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        return sum;
    }
}
